package com.demo2.bean;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

// ========== 2. License信息类 ==========
public class LicenseInfo {
    private String customerName;
    private String productName;
    private String productVersion;
    private String expiryDate;
    private String machineId;
    private int maxUsers;
    private Map<String, Object> features;
    
    public LicenseInfo(String customerName, String productName, String productVersion, 
                      String expiryDate, String machineId, int maxUsers) {
        this.customerName = customerName;
        this.productName = productName;
        this.productVersion = productVersion;
        this.expiryDate = expiryDate;
        this.machineId = machineId;
        this.maxUsers = maxUsers;
        this.features = new HashMap<>();
    }
    
    // Getters and Setters
    public String getCustomerName() { return customerName; }
    public void setCustomerName(String customerName) { this.customerName = customerName; }
    
    public String getProductName() { return productName; }
    public void setProductName(String productName) { this.productName = productName; }
    
    public String getProductVersion() { return productVersion; }
    public void setProductVersion(String productVersion) { this.productVersion = productVersion; }
    
    public String getExpiryDate() { return expiryDate; }
    public void setExpiryDate(String expiryDate) { this.expiryDate = expiryDate; }
    
    public String getMachineId() { return machineId; }
    public void setMachineId(String machineId) { this.machineId = machineId; }
    
    public int getMaxUsers() { return maxUsers; }
    public void setMaxUsers(int maxUsers) { this.maxUsers = maxUsers; }
    
    public Map<String, Object> getFeatures() { return features; }
    public void setFeatures(Map<String, Object> features) { this.features = features; }
    
    public void addFeature(String key, Object value) {
        this.features.put(key, value);
    }
    
    // 转换为字符串格式用于签名
    public String toLicenseString() {
        StringBuilder sb = new StringBuilder();
        sb.append("customerName=").append(customerName).append("\n");
        sb.append("productName=").append(productName).append("\n");
        sb.append("productVersion=").append(productVersion).append("\n");
        sb.append("expiryDate=").append(expiryDate).append("\n");
        sb.append("machineId=").append(machineId).append("\n");
        sb.append("maxUsers=").append(maxUsers).append("\n");
        
        for (Map.Entry<String, Object> entry : features.entrySet()) {
            sb.append("feature.").append(entry.getKey()).append("=").append(entry.getValue()).append("\n");
        }
        
        sb.append("issueDate=").append(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)).append("\n");
        return sb.toString();
    }
}
